package firstPack;

import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;

/**
 * Prints out an ordered list of high scores using a helpful
 * ordering function from the GameState class. Returns to the
 * main menu when space is pressed.
 * State 4
 * @author El Jefe
 *
 */
public class HighScoreDisp extends BasicGameState{

	private ArrayList<Integer> orderPrint;
	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		orderPrint = new ArrayList<Integer>();
		
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics disp)
			throws SlickException {
		StringBuilder scoreDisplay = new StringBuilder();
		orderPrint = GameState.sortScores();
		for(Integer keys : orderPrint){
			scoreDisplay.append(GameState.highScores.get(keys) + " " + keys + "\n");
		}
//		for (Integer keys : GameState.highScores.keySet()){
//			scoreDisplay.append(GameState.highScores.get(keys) + " " + keys + "\n");
//		}
		disp.drawString("High Scores :\n" + scoreDisplay + "\n\nPress spacebar to return", 200, 100);
		
	}

	@Override
	public void update(GameContainer container, StateBasedGame sbg, int delta)
			throws SlickException {
		Input input = container.getInput();
		if(input.isKeyPressed(input.KEY_SPACE)){
			input.clearKeyPressedRecord();
			sbg.enterState(0, new FadeOutTransition(), new FadeInTransition());
		}
		
	}

	@Override
	public int getID() {
		// TODO Auto-generated method stub
		return 4;
	}

}
